<template>
  <el-dialog
    :visible.sync="param.visible"
    title="修改基本信息"
    center
    @close="param.close"
    :close-on-click-modal="false"
  >
    <Form1
      ref="editForm"
      :rules="rules"
      :form="param.editForm"
      :items="items"
      :save="doUpdate"
    >
    </Form1>
  </el-dialog>
</template>
<script>
import Form1 from "@/components/Form1.vue";

export default {
  name: "Edit",
  components: { Form1 },

  props: {
    param: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      rules: {
        name: [{ required: true, message: "必填项不能为空" }],
      },
      items: [
        {
          type: "text",
          label: "名称",
          prop: "name",
          name: "name",
          placeholder: "请输入单位名称",
        },
        {
          type: "text",
          label: "联系人",
          prop: "contact",
          name: "contact",
          placeholder: "请输入单位联系人",
          options: [],
        },
        {
          type: "text",
          label: "联系电话",
          prop: "telephone",
          name: "telephone",
          placeholder: "请输入联系电话",
        },
        {
          type: "text",
          label: "邮箱",
          prop: "email",
          name: "email",
          placeholder: "请输入邮箱",
        },
        {
          type: "text",
          label: "地址",
          prop: "addr",
          name: "addr",
          placeholder: "请输入地址",
        },

        {
          type: "text",
          label: "网址",
          prop: "url",
          name: "url",
          placeholder: "请输入网址",
        },
        {
          type: "select",
          label: "规模",
          prop: "size",
          name: "size",
          placeholder: "请输入规模",
          options: [],
        },
        {
          type: "select",
          label: "公司类型",
          prop: "type",
          name: "type",
          placeholder: "请输入公司类型",
          options: [],
        },
        {
          type: "file",
          label: "Logo",
          prop: "logo",
          name: "logo",
          placeholder: "请输入Logo",
        },
        {
          type: "area",
          label: "公司描述",
          prop: "description",
          name: "description",
          placeholder: "请输入内容",
        },
      ],
    };
  },
  mounted() {
    this.getDictList(4);
    this.getDictList(5);
  },
  created() {},
  methods: {
    // 获取字典列表
    getDictList(typeId) {
      this.postRequest("/dict/query/", { type_id: typeId }).then((res) => {
        if (res) {
          if (typeId == 4) {
            //类型
            let arr = [];
            res.forEach((item) => {
              let p = { value: item.dict_key, label: item.dict_val };
              arr.push(p);
            });
            this.items.forEach((item) => {
              if (item.type == "select" && item.name == "type") {
                item.options = arr;
              }
            });
          } else if (typeId == 5) {
            // 规模
            let arr = [];
            res.forEach((item) => {
              let p = { value: item.dict_key, label: item.dict_val };
              arr.push(p);
            });
            this.items.forEach((item) => {
              if (item.type == "select" && item.name == "size") {
                item.options = arr;
                console.log(arr, "类型");
              }
            });
          }
          console.log(res, "=======类型是", typeId);
        }
      });
    },
    //   修改
    doUpdate() {
      let flag = this.$refs["editForm"].validateForm();
      this.$emit("doUpdate", flag);
    },
  },
};
</script>
<style></style>
